
/**
 * 表示站名的类
 */
Subwaymap.StationName = org.gridsofts.util.Class.define({
    name: "Subwaymap.StationName",

    /**
     * 构造函数
     */
    construct: function (container, station, group) {
        if (arguments.length == 0 || typeof (arguments[0]) != "object") {
            throw new Error("Object construct parameter is empty, unable to initialize instance of Station.");
        }

        this.container = container;
        this.station = station;
        this.group = group;

        this.color = "#252e3c";
        this.repaint();
    },

    /**
     * 方法
     */
    methods: {
        repaint: function () {
            this.actualDrawStation();
        },

        /** 
         * 调用绘图API，在画布上绘制图元
         */
        actualDrawStation: function () {
            // 当前只 针对  top  right  属性， 统称为  X  Y  坐标定位，此操作简单，避免又出现  left bottom ,增加代码传值判断
            var subStation = this.station;
            if (subStation.exchangeStop) {
                var getCacheStation = getLocalStorage(subStation.stopName);
                if (!getCacheStation) {
                    setLocalStorage(subStation.stopName, subStation.stopName + "-" + subStation.routeMapStopID);
                }
            }

            // 1. 虚拟站隐藏
            // 2. 如果是换乘站，则只显示第一个存入缓存的站点 描述信息
            if ((!subStation.virtualStop && !subStation.exchangeStop) ||
                (!subStation.virtualStop && subStation.exchangeStop && getLocalStorage(subStation.stopName) == (subStation.stopName + "-" + subStation.routeMapStopID))
            ) {
                var text = new Kinetic.Text({
                    x: this.station.stopX,
                    y: this.station.stopY,
                    fontVariant: 'small-caps',
                    align: 'center',
                    fontSize: 28,
                    fontFamily: 'Arial',
                    fill: this.color
                });

                if (!this.station.hideStopName && !this.station.publishedStop) {
                    text.setText(this.station.stopName + "\n" + this.station.stopChiName ?? "");
                }
                var width = text.width();
                var heigth = text.height();
                var top = this.station.nameTop;
                var right = this.station.nameRight;
                if (typeof (right) != "undefined" && null != right && 0 != right && typeof (top) != "undefined" && null != top && 0 != top) {  //右上
                    text.x(text.x() + right);
                    text.y(text.y() - top - heigth);
                }
                else {
                    if (typeof (top) != "undefined" && null != top && 0 != top) {
                        text.y(text.y() - top - heigth);
                        text.x(text.x() - width / 2);
                    }
                    if (typeof (right) != "undefined" && null != right && 0 != right) {
                        text.x(text.x() + right);
                        text.y(text.y() - heigth / 2);  //上下居中
                    }
                }

                text.addEventListener("click", function () {
                    return false;
                });

                this.group.add(text);
                this.container.add(this.group);
            }
        },
    }
});